package com.upeoe.shiro.chapter2;

import org.apache.shiro.authz.UnauthorizedException;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author ven_hxz
 * @create 2016-07-03 下午12:08
 */
public class PermissionTutorial extends LoginHelper {

    @Test
    public void testIsPermitted() {
        login("classpath:shiro-permission.ini", "root", "root");

        Assert.assertTrue(getSubject().isPermitted("user:create"));
        Assert.assertTrue(getSubject().isPermittedAll("user:update", "user:delete"));
        Assert.assertFalse(getSubject().isPermitted("user:view"));
    }

    @Test(expected = UnauthorizedException.class)
    public void testCheckPermission() {
        login("classpath:shiro-permission.ini", "root", "root");

        getSubject().checkPermission("user:create");
        getSubject().checkPermissions("user:update", "user:delete");
        getSubject().checkPermission("user:view");
    }
}
